package com.qf.hotel.dao.impl;

import com.qf.hotel.dao.MenuDao;
import com.qf.hotel.pojo.Menu;
import com.qf.hotel.utils.JdbcUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

/**
 * @author: GsheN丶
 * @date: 2021/6/23 14:46
 * @description:Menu持久层实现类
 */
public class MenuDaoImpl implements MenuDao {



    QueryRunner queryRunner = new QueryRunner(JdbcUtils.getDataSource());

    /**
     *
     * @author: GsheN丶
     * @date: 2021/6/23 14:47
     * @description:实现查询的所有操作
     */
    @Override
    public List<Menu> findAll() throws SQLException {
        String sql = "SELECT menu_id as menuId ,menu_name as menuName,menu_URL as menuUrl FROM t_menu";

        //执行查询得到结果
        return queryRunner.query(JdbcUtils.getConnection(),sql,new BeanListHandler<>(Menu.class));

    }
}
